home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 289_01.zip / BD_EVAL.C next >
Text File  |  1993-04-26  |  3KB  |  96 lines

  1. /*-----------------------------------------------------------------------------
  2. Calculate the score for a board.
  3.  
  4. Revision History
  5. ----------------
  6. Gary Culp   15 Dec 1988    Initial version.
  7. Gary Culp   29 Jan 1989    Added code to discourage giving the opponent
  8.                            a bridge to the corner.
  9. -----------------------------------------------------------------------------*/
  10.  
  11. #include "othello.h"
  12.  
  13. struct special_score_struct {
  14.    int offset;
  15.    unsigned char flags;
  16. };
  17.  
  18. /*
  19. Calculate the score for a board.
  20. The board must have already been updated.
  21. */
  22. int
  23. bd_eval(struct board_struct *board_ptr,
  24.         unsigned char which_color)
  25. {
  26.    register int score = 0;
  27.  
  28.    {
  29.       register unsigned char *cell_ptr;
  30.       unsigned char *stop;
  31.  
  32.       stop = &board_ptr->board[8][9];
  33.       for (cell_ptr = &board_ptr->board[1][1]; cell_ptr < stop; cell_ptr++) {
  34.          switch (*cell_ptr & (unsigned char)(US_PIECE | THEM_PIECE)) {
  35.  
  36.          case US_PIECE :
  37.             score++;
  38.             if (IS_PERM(*cell_ptr)) {
  39.                score += 15;
  40.             }
  41.             break;
  42.  
  43.          case THEM_PIECE :
  44.             score--;
  45.             if (IS_PERM(*cell_ptr)) {
  46.                score -= 15;
  47.             }
  48.             break;
  49.          }
  50.       }
  51.    }
  52.  
  53.    {
  54.       register struct special_score_struct *ssptr;
  55.       static struct special_score_struct avoid_adj_corner[12] = {
  56.          {12, H_AX  | US_PIECE | THEM_PIECE},
  57.          {21, V_AX  | US_PIECE | THEM_PIECE},
  58.          {22, BD_AX | US_PIECE | THEM_PIECE},
  59.  
  60.          {17, H_AX  | US_PIECE | THEM_PIECE},
  61.          {27, FD_AX | US_PIECE | THEM_PIECE},
  62.          {28, V_AX  | US_PIECE | THEM_PIECE},
  63.  
  64.          {71, V_AX  | US_PIECE | THEM_PIECE},
  65.          {72, FD_AX | US_PIECE | THEM_PIECE},
  66.          {82, H_AX  | US_PIECE | THEM_PIECE},
  67.  
  68.          {77, BD_AX | US_PIECE | THEM_PIECE},
  69.          {78, V_AX  | US_PIECE | THEM_PIECE},
  70.          {87, H_AX  | US_PIECE | THEM_PIECE}
  71.       };
  72.  
  73.       for (ssptr = &avoid_adj_corner[0];
  74.            ssptr < &avoid_adj_corner[
  75.               sizeof(avoid_adj_corner)/sizeof(struct special_score_struct)];
  76.            ssptr++)
  77.       {
  78.          switch (board_ptr->board[0][ssptr->offset] & ssptr->flags) {
  79.          case US_PIECE :
  80.             /* We have a piece adjacent to a corner, which is not protected
  81.                along the axis it shares with the corner. This is a risky
  82.                situation, so we deduct some points for it.
  83.             */
  84.             score -= 5;
  85.             break;
  86.          case THEM_PIECE :
  87.             score += 5;
  88.             break;
  89.          }
  90.       }
  91.    }
  92.  
  93.    return (which_color == US_PIECE ? score : -score);
  94. }
  95.  
  96.